/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ruipengkj.bean.ViewProfitCommoditySummary;
import com.ruipengkj.commons.base.query.BaseQuery;
import com.ruipengkj.commons.base.query.PageModel;
import com.ruipengkj.dao.ViewProfitCommoditySummaryDao;
import com.ruipengkj.service.ViewProfitCommoditySummaryService;
/**
 * 说明：
 * 供货单明细汇总表Service层接口实现
 * @Author：李智深
 * @Date：2012-03-16
 */
@Service
public class ViewProfitCommoditySummaryServiceImpl implements ViewProfitCommoditySummaryService{

	@Resource
	private ViewProfitCommoditySummaryDao ViewProfitCommoditySummaryDao;//DAO层
	
	//根据条件查询
	@Override
	public List<ViewProfitCommoditySummary> findService(ViewProfitCommoditySummary entity) throws Exception {
		String hql = "select o from ViewProfitCommoditySummary o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return ViewProfitCommoditySummaryDao.findDao(hql, whereHQL.toString(), param, orderby);
	}

	//根据ID翻页查询
	@Override
	public PageModel<ViewProfitCommoditySummary> getScrollService(int firstResult,
			int maxResult, ViewProfitCommoditySummary entity) throws Exception {
		String hql = "select o from ViewProfitCommoditySummary o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getName()!=null&&!entity.getName().equals("")){
				whereHQL.append("o.name").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getName()+"%");
			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return ViewProfitCommoditySummaryDao.getScrollDao(hql, whereHQL.toString(), param, firstResult, maxResult, orderby);
	}

	//修改
	@Override
	public void modifyService(ViewProfitCommoditySummary entity) throws Exception {
		ViewProfitCommoditySummaryDao.modifyDao(entity);
		
	}
	//添加
	@Override
	public void saveService(ViewProfitCommoditySummary entity) throws Exception {
		ViewProfitCommoditySummaryDao.saveDao(entity);
	}

	//根据ID删除
	@Override
	public void deleteService(String id) throws Exception {
		ViewProfitCommoditySummaryDao.deleteDao(id);
		
	}
	//根据ID查询
	@Override
	public ViewProfitCommoditySummary getByIdService(String id) throws Exception {
		return ViewProfitCommoditySummaryDao.getByIdDao(id);
	}
	//添加或修改
	@Override
	public void saveOrUpdateService(ViewProfitCommoditySummary entity) throws Exception {
		ViewProfitCommoditySummaryDao.saveOrUpdateDao(entity);
	}
	//添加返回ID
	@Override
	public Serializable saveRetService(ViewProfitCommoditySummary entity) throws Exception {
		return ViewProfitCommoditySummaryDao.saveRetDao(entity);
	}

	public ViewProfitCommoditySummaryDao getViewProfitCommoditySummaryDao() {
		return ViewProfitCommoditySummaryDao;
	}

	public void setViewProfitCommoditySummaryDao(
			ViewProfitCommoditySummaryDao ViewProfitCommoditySummaryDao) {
		this.ViewProfitCommoditySummaryDao = ViewProfitCommoditySummaryDao;
	}

	@Override
	public List<ViewProfitCommoditySummary> findExportService(
			ViewProfitCommoditySummary entity) throws Exception {
		String hql = "select o from ViewProfitCommoditySummary o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getName()!=null&&!entity.getName().equals("")){
				whereHQL.append("o.name").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getName()+"%");
			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return ViewProfitCommoditySummaryDao.findDao(hql, whereHQL.toString(), param, orderby);
	}
}
